--[[
    @desc 栈 下标由0到n-1
    @author zch
    @data:2022-04-20 14:00:00
]]

local Stack = Stack or BaseClass()
-- local Stack = Stack
local table_insert = table.insert
local table_remove = table.remove

function Stack:__init()
	self.size = 0
	self.items = {}
end

-- 栈顶插入一个值
function Stack:Push(item)
	self.size = self.size + 1
	self.items[self.size] = item
end

-- 栈顶移除一个值 并返回
function Stack:Pop()
	if self.size > 0 then
		local item = self.items[self.size]
		self.items[self.size] = nil
		self.size = self.size - 1
		return item
	end
	return nil
end

-- 栈顶获得一个值 并返回
function Stack:Peek()
	if self.size > 0 then
		local item = self.items[self.size]
		return item
	end
	return nil
end

function Stack:Contains(item)
	for i = 1, self.size do
		local _item = self.items[i]
		if _item == item then return true end
	end
	return false
end

function Stack:Clear()
	self.size = 0
	self.items = {}
end

function Stack:GetSize()
	return self.size
end

function Stack:IsEmpty()
	return self.size <= 0
end

return Stack